package com.cskaoyan.controller.admin;
import com.cskaoyan.bean.MarketTopic;
import com.cskaoyan.bean.bo.admin.topic.TopicDelBo;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.admin.topic.ShowTopicInfo;
import com.cskaoyan.service.admin.TopicService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


/**
 * @author by yxy_8175@163.com
 * @Description TODO
 * @Date 2022-11-20 14:52
 */

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    TopicService topicService;

    /**
     * 展示topic页面，包括分页查询以及条件模糊查询
     * @return
     * @auto  yxy_8175@163.com
     */
    @RequestMapping("list")
    public BaseRespVo showAllTopicInfo(BasePageInfo info, String title, String subtitle){

        CommonData<MarketTopic> commonData = topicService.selectByPage(info,title,subtitle);

        return BaseRespVo.ok(commonData);
    }

    /**
     * 创建topic
     * @param topic
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo createTopicInfo(@RequestBody MarketTopic topic){
        MarketTopic resultTopic = topicService.createTopic(topic);

        return BaseRespVo.ok(resultTopic);
    }
/*
 * @Description 获取网页信息
 * @param id
 * @return
 * @date 2022-11-20 20:51
 * @auther yxy_8175@163.com
*/
    @RequestMapping("read")
    public BaseRespVo selectTopicDetailInfo(Integer id){
        ShowTopicInfo info = topicService.selectTopicById(id);

        return BaseRespVo.ok(info);
    }
/*
 * @Description 更新信息
 * @param
 * @return
 * @date 2022-11-20 20:51
 * @auther yxy_8175@163.com
*/
    @RequestMapping("update")
    public BaseRespVo updateTopic(@RequestBody MarketTopic topic){
        MarketTopic resultTopic = topicService.updateTopicInfo(topic);

        return BaseRespVo.ok(resultTopic);
    }

    /*
     * @Description 删除topic信息  -  逻辑删除
     * @param
     * @return
     * @date 2022-11-20 20:51
     * @auther yxy_8175@163.com
    */
    @RequestMapping("delete")
    public BaseRespVo deleteTopic(@RequestBody MarketTopic topic){
        int status = topicService.deleteTopic(topic);

        if (status == BaseRespVo.STATUS_OK) {
            return BaseRespVo.ok();
        }

        return BaseRespVo.invalidData("删除失败...");
    }

    /*
     * @Description 批量删除
     * @param
     * @return
     * @date 2022-11-21 9:43
     * @auther yxy_8175@163.com
    */
    @RequestMapping("batch-delete")
    public BaseRespVo deleteMultipleTopic(@RequestBody TopicDelBo topicDels){

        topicService.deleteTopicMultiple(topicDels.getIds());
        return BaseRespVo.ok();
    }
}
